    package com.springboot.springbootlogindemo.utils;



    //存放工具类，一些自己封装的工具
    //工具类Result的作用是作为返回给前端的统一后的对象。也就是说返回给前端的都是Result对象，只是对象中的属性不太一样，这样方便前端固定接收格式。
    public class Result<T> {
        private String code;
        private String msg;
        private T data;

        public String getCode() {
            return code;
        }

        public void setCode(String code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }

        public Result() {
        }

        public Result(T data) {
            this.data = data;
        }

        public static Result success() {
            Result result = new Result<>();
            result.setCode("0");
            result.setMsg("成功");
            return result;
        }

        public static Result success(String msg){
            Result result=new Result<>();
            result.setCode(("0"));
            result.setMsg(msg);
            return result;
        }

        public static <T> Result<T> success(T data) {
            Result<T> result = new Result<>(data);
            result.setCode("0");
            result.setMsg("成功");
            return result;
        }

        public static <T> Result<T> success(T data,String msg) {
            Result<T> result = new Result<>(data);
            result.setCode("0");
            result.setMsg(msg);
            return result;
        }

        public static Result error(String code, String msg) {
            Result result = new Result();
            result.setCode(code);
            result.setMsg(msg);
            return result;
        }
        public static Result error(String msg) {
            Result result = new Result();
            result.setMsg(msg);
            return result;
        }
    }
    /*
    可以看出Result是个模板类，因此想要返回什么数据类型给前端都行
    如Result<User>，要是没看懂没关系,看到下面就知道怎么用了。
    因为里面有很多静态方法，可以直接用类名.方法名调用。
     */
